package com.learn.project2.controller.admin;

import com.learn.project2.model.vo.admin.config.ConfigExpressVO;
import com.learn.project2.model.vo.admin.config.ConfigMallVO;
import com.learn.project2.model.vo.admin.config.ConfigOrderVO;
import com.learn.project2.model.vo.admin.config.ConfigWxVO;
import com.learn.project2.service.admin.config.ConfigService;
import com.learn.project2.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 尹圣淼
 * @Date: 2022/1/6 21:55
 * @:
 */
@RestController
@RequestMapping("admin/config")
public class ConfigController {

    @Autowired
    ConfigService configService;

    /**
     * @description: 71.商城配置 admin/config/mall
     * @param:
     * @return:
     * @author 尹圣淼
     * @date: 2022-01-06 22:09
     */
    @RequestMapping(value = "mall", method = RequestMethod.GET)
    @RequiresPermissions(value = "admin:config:mall:list")
    public Result mallGet() {
        // 然后查询信息之后封装到对象中。发出响应。
        // select key_name,key_value from market_system
        /* *   <where>
         *       <foreach collection="" item="name" >
         *           <!--数组中元素是key_name 名字。得到id,然后id对应的key_value值。-->
         *           key_name = #{name}
         *       </foreach>
         *   </where>
         * */
        ConfigMallVO configMallVO = configService.mallShow();
        return Result.ok(configMallVO);
    }

    @RequiresPermissions(value = "admin:config:mall:updateConfigs")
    @RequestMapping(value = "mall", method = RequestMethod.POST)
    public Result mallPost(@RequestBody ConfigMallVO configMallVO) {
        //{"market_mall_longitude":"121.587839","market_mall_latitude":"31.201900",
        // "market_mall_address":"武汉","market_mall_qq":"139310186",
        // "market_mall_phone":"021-xxxx-xxxx","market_mall_name":"f"}
        // 更改信息，最终响应出新数据
        return configService.mallUpdate(configMallVO);
    }

    /**
     * @description: 72.运费配置 -> admin/config/express
     * @param:
     * @return:
     * @author 尹圣淼
     * @date: 2022-01-06 22:12
     */

    @RequiresPermissions(value = "admin:config:express:list")
    @RequestMapping(value = "express", method = RequestMethod.GET)
    public Result expressGet() {
        // get方法直接通过数据库拿到变量值 再送出去
        ConfigExpressVO configExpressVO = configService.expressShow();
        return Result.ok(configExpressVO);
    }

    @RequiresPermissions(value = "admin:config:express:updateConfigs")
    @RequestMapping(value = "express", method = RequestMethod.POST)
    public Result expressPost(@RequestBody ConfigExpressVO configExpressVO) {

        return configService.expressUpdate(configExpressVO);
    }

    /**
     * @description: 73.订单配置 -> admin/config/order
     * @param:
     * @return:
     * @author 尹圣淼
     * @date: 2022-01-06 22:12
     */
    @RequiresPermissions(value = "admin:config:order:list")
    @RequestMapping(value = "order", method = RequestMethod.GET)
    public Result orderGet() {
        // 通过数据库查找 封装对象 响应出去。
        ConfigOrderVO configOrderVO = configService.orderShow();
        return Result.ok(configOrderVO);
    }
    @RequiresPermissions(value = "admin:config:order:updateConfigs")
    @RequestMapping(value = "order", method = RequestMethod.POST)
    public Result orderPost(@RequestBody ConfigOrderVO configOrderVO) {
        return configService.orderUpdate(configOrderVO);
    }

    /**
     * @description: 74.小程序配置 -> admin/config/wx
     * @param:
     * @return:
     * @author 尹圣淼
     * @date: 2022-01-06 22:16
     */
    @RequiresPermissions(value = "admin:config:wx:list")
    @RequestMapping(value = "wx", method = RequestMethod.GET)
    public Result wxGet() {
        ConfigWxVO configWxVO = configService.wxShow();
        return Result.ok(configWxVO);
    }

    @RequiresPermissions(value = "admin:config:wx:updateConfigs")
    @RequestMapping(value = "wx", method = RequestMethod.POST)
    public Result wxPost(@RequestBody ConfigWxVO configWxVO) {
        return configService.wxUpdate(configWxVO);
    }
}
